package com.qf.servlet;

import com.qf.entity.Classes;
import com.qf.service.ClassesService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 班级新增的servlet
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/classesinsert")
public class ClassesInsertServlet extends HttpServlet {

    private ClassesService classesService = new ClassesService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String className = req.getParameter("className");

        //封装到实体类
        Classes classes = new Classes();
        classes.setClassName(className);

        //调用service
        int result = classesService.insertCls(classes);
        if (result > 0) {
            //重定向到 班级列表查询的Servlet
            resp.sendRedirect("classsequery");
        } else {
            //添加失败
            resp.sendRedirect("classesinsert.jsp?status=1");
        }
    }
}
